package br.upe.dsc.caeto.core.application;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import br.upe.dsc.caeto.core.IRepository;

public class ApplicationRepositoryList extends LinkedList<Application>
                                       implements IRepository<Application>,
                                                  Iterable<Application> {
	
	public ApplicationRepositoryList() {
		super();
	}
	
	public void insert(Application application) {
		if (application != null) {
			add(application);
		}
	}
	
	public void remove(Application application) {
		if (application != null) {
			super.remove(application);
		}
	}
	
	public void update(Application application) {
		if (application != null) {
			remove(application);
			insert(application);
		}
	}
	
	public Application search(String name) {
		if (name != null) {
			for (Application application : this) {
				if (application.getName().equals(name)) {
					return application;
				}
			}
		}
		return null;
	}
	
	public boolean isElement(String name) {
		if (name != null) {
			for (Application application : this) {
				if (application.getName().equals(name)) {
					return true;
				}
			}
		}
		return false;
	}
	
	public void empty() {
		clear();
	}
	
	public Iterator<Application> iterator() {
		return listIterator();
	}
	
	public Iterable<Application> getElements() {
		return this;
	}
}